package com.zyy.smartcity1129.reservation;

import android.content.Context;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.MutableLiveData;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.LoginActivity;
import com.zyy.smartcity1129.MainActivity;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.util.Http;

/**
 * @ClassName: ReservationFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 29/11/2021$
 * @Version: 1.0
 */
public class ReservationFragment extends BaseFragment {
    private FrameLayout frameReser;
    public static BottomNavigationView bottomReser;
    public static MutableLiveData<String> mutableLiveData = new MutableLiveData<>();

    @Override
    protected int layId() {
        return R.layout.f_reservation;
    }

    @Override
    protected String title() {
        return "预约检车";
    }

    @Override
    protected boolean back() {
        return true;
    }

    @Override
    protected Boolean bottom() {
        return true;
    }

    @Override
    protected void init(View iv) {
        initView(iv);
        Http.base = "http://124.93.196.45:10001";
        Http.token = MainActivity.mToken;
        mutableLiveData.observe(getViewLifecycleOwner(), s -> {
            title.setText(s);
        });
        getActivity().getSupportFragmentManager().beginTransaction().add(R.id.frameReser, new ReserMainFragment()).commit();
        bottomReser.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.itemNotice:
                        add(new ReserMainFragment());
                        break;
                    case R.id.itemReser:
                        add(new ReserNowFragment());
                        break;
                    case R.id.itemMyReser:
                        add(new ReserMyFragment());
                        break;
                    case R.id.itemCar:
                        add(new ReserManageFragment());
                        break;
                }
                return true;
            }
        });
    }

    public void add(Fragment fragment) {
        getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.frameReser, fragment).commit();
    }

    private void initView(View view) {
        frameReser = (FrameLayout) view.findViewById(R.id.frameReser);
        bottomReser = (BottomNavigationView) view.findViewById(R.id.bottomReser);
    }
}
